﻿using System;
using Duhking;
using NUnit.Framework;

namespace Duhking.Tests
{
    [TestFixture]
    public class DuhkingExtensionsTests
    {
        public interface PropertyInterface
        {
            string Name { get; }
            Guid Id { get; }
        }

        public class AlmostDisposable
        {
            public void Dispose()
            {
            }
        }

        [Test]
        public void CanBe_Returns_True_If_Object_Has_Matching_Methods()
        {
            var almostDisposable = new AlmostDisposable();
            Assert.That(almostDisposable.CanBe<IDisposable>(),Is.True);
        }

        [Test]
        public void CanBe_Returns_False_If_Object_Does_Not_Have_Matching_Methods()
        {
            var newObj = new { Name = "Bob" };
            Assert.That(newObj.CanBe<IDisposable>(),Is.False);
        }

        [Test]
        public void AsType_Returns_A_Proxy_Of_The_Requested_Interface_Type()
        {
            var almostDisposable = new AlmostDisposable();
            Assert.That(almostDisposable.AsType<IDisposable>(), Is.InstanceOf<IDisposable>());
        }

        [Test]
        public void AsType_Can_Generate_A_Duhk_For_An_Anonymous_Type()
        {
            var newType = new { Name = "Sam", Id = Guid.NewGuid() };
            PropertyInterface duhkedType = newType.AsType<PropertyInterface>();
            Assert.That(duhkedType.Name, Is.EqualTo(newType.Name));
            Assert.That(duhkedType.Id, Is.EqualTo(newType.Id));
        }
    }
}
